package str837_checkbox_group;

import java.applet.Applet;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Graphics;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class Main extends Applet implements ItemListener {
	private String msg = "";
	private Checkbox winXP, win7, solaris, mac;
	private CheckboxGroup cbg;
	
	@Override
	public void init() {
		setSize(500, 300);
		cbg = new CheckboxGroup();
		winXP = new Checkbox("Windows XP", cbg, true);
		win7 = new Checkbox("Windows 7", cbg, false);
		solaris = new Checkbox("Solaris", cbg, false);
		mac = new Checkbox("MacOS", cbg, false);
		
		add(winXP);
		add(win7);
		add(solaris);
		add(mac);
		
		winXP.addItemListener(this);
		win7.addItemListener(this);
		solaris.addItemListener(this);
		mac.addItemListener(this);
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		repaint();
	}

	@Override
	public void paint(Graphics g) {
		msg = "Aktualnie wybrana opcja: ";
		msg += cbg.getSelectedCheckbox().getLabel();
		g.drawString(msg, 6, 100);
	}
	
	
}
